package com.reservationserver.controller.admin;

import com.reservationpojo.domin.po.Getmgrpo;
import com.reservationpojo.domin.po.Getuserpo;
import com.reservationpojo.domin.vo.Adduservo;
import com.reservationpojo.domin.vo.Getmgrvo;
import com.reservationpojo.domin.vo.Getuservo;
import com.reservationpojo.domin.vo.UpTextvo;
import com.reservationpojo.entity.User;
import com.reservationpojo.utils.Result;
import com.reservationserver.service.admin.Mgrservice;
import com.reservationserver.service.admin.Textservice;
import com.reservationserver.service.user.Userservice;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/reservation/mgr")
@Tag(name = "管理员")
public class Mgrcontroller {
    private final Userservice userservice;
    private final Mgrservice mgrservice;
    private final Textservice textservice;

//    /**
//     * 管理员添加学生
//     * @param uservo
//     * @return
//     */
//    @PostMapping
//    @Operation(summary = "新增用户")
//    public Result adduser(@RequestBody Adduservo uservo){
//        log.info("按照id或empname查询:{}", uservo);
//        userservice.adduser(uservo);
//        return Result.success();
//    }

    /**
     * 分页查询用户
     * @param getuservo
     * @return
     */
    @GetMapping("/getuser")
    @Operation(summary = "查看用户")
    public Result getusercontroller(@RequestBody Getuservo getuservo) {
        log.info("按照id或empname查询:{}", getuservo);
        Getuserpo userpo=userservice.getUserservice(getuservo);
        return Result.success(userpo);
    }

    /**
     * 分页查询管理员
     * @param getmgrvo
     * @return
     */
    @GetMapping("/getmgr")
    @Operation(summary = "查看管理员")
    public Result getmgrcontroller(@RequestBody Getmgrvo getmgrvo) {
        log.info("按照id或empname查询:{}", getmgrvo);
        Getmgrpo mgrpo=mgrservice.getmgr(getmgrvo);
        return Result.success(mgrpo);
    }

    /**
     * 拉黑用户
     * @param id
     * @return
     */
    @PutMapping("/upblack")
    @Operation(summary = "拉黑用户")
    public Result black(@RequestParam String id){
        log.info("按照id或empname查询:{}", id);
        userservice.black(id);
        return Result.success();
    }

    /**
     * 移除黑名单
     * @param id
     * @return
     */
    @PutMapping("/upunblack")
    @Operation(summary = "移除黑名单")
    public Result unblack(@RequestParam String id){
        log.info("按照id或empname查询:{}", id);
        userservice.unblack(id);
        return Result.success();
    }

    /**
     * 根据公告类别修改公告
     * @param upTextvo
     * @return
     */
    @Operation(summary = "修改公告")
    @PutMapping("/uptext")
    public Result uptext(@RequestBody UpTextvo upTextvo){
        textservice.uptest(upTextvo);
        return Result.success();
    }

    /**
     * 删除用户
     * @param userIds
     * @return
     */
    @Operation(summary = "删除用户")
    @DeleteMapping("/deleteuser")
    public Result deleteuser(@RequestParam List<String> userIds){
        log.info("id-list{}",userIds);
        userservice.deleteuser(userIds);
        return Result.success();
    }
    /**
     * 给予门禁管理员权限
     * @param id
     * @return
     */
     @Operation(summary = "给予门禁管理权限")
     @PutMapping("/upguard")
     public Result upguard(String id){
         userservice.upguard(id);
         return Result.success();
     }

     /*
      * 撤销门禁管理员权限
      * @param id
     * @return
     */
     @Operation(summary = "撤销门禁管理权限")
     @PutMapping("/upunguard")
     public Result upunguard(String id){
         userservice.upunguard(id);
         return Result.success();
     }
}

